package com.shenzhen.horselive.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.api.ApiService;
import com.shenzhen.horselive.api.response.MyInfoResponse;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.CommResponseBean;
import com.shenzhen.horselive.databinding.ActivityMyBankBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;

public class MyBankActivity extends AppBarActivity {

    ActivityMyBankBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding =ActivityMyBankBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("我的银行卡");
        initViews();
    }

    private void initViews() {
        binding.btGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                submit();
            }
        });
    }

    private void submit() {
        String  name =  binding.etName.getText().toString();
        if (TextUtils.isEmpty(name))
        {
            return;
        }

        String  zhanghao =  binding.etZhanghao.getText().toString();
        if (TextUtils.isEmpty(zhanghao))
        {
            return;
        }

//        String  bankname =  binding.etBankName.getText().toString();
//        if (TextUtils.isEmpty(bankname))
//        {
//            return;
//        }

        String  phone =  binding.etYuliuPhone.getText().toString();
        if (TextUtils.isEmpty(phone))
        {
            return;
        }

        ApiFactory.getApiService().setBank(User.get().getMyInfo().getToken()
        ,zhanghao,phone).compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<CommResponseBean>(this) {
                    @Override
                    protected void onNextInActive(CommResponseBean commResponseBean) {
                        if (commResponseBean.isSuccess())
                        {
                            showToast("设置成功");
                            MyInfoResponse   myInfoResponse = User.get().getMyInfo();
                            myInfoResponse.setCardNo("121211212121");
                            User.get().storeMyInfo(myInfoResponse);
                            setResult(1001);
                            finish();
                        }else
                        {
                            showToast(commResponseBean.getErrMessage());
                        }
                    }
                });







    }
}